var a = require("../template/index.js"), e = getApp(), t = {
    data: {
        msg_template: "检测到您的账号还未绑定手机，请绑定手机号",
        sure_template: "绑定手机号",
        hidden_msg: !1,
        livevideo: !1
    },
    getUserInfoHandle: function(a) {
        if (this.setData({
            livevideo: !1
        }), "getUserInfo:ok" === a.detail.errMsg) {
            var t = a.detail.userInfo;
            wx.request({
                method: "post",
                header: {
                    "content-type": "application/x-www-form-urlencoded"
                },
                url: e.globalData.uchaozuBase + "/api/miniapps/login/update-user",
                data: Object.assign({
                    nick_name: t.nickName,
                    avatar_url: t.avatarUrl,
                    user_id: e.globalData.userInfo.user_id
                }, e.getSecret()),
                complete: function(a) {
                    wx.navigateBack(), e.globalData.userInfo.avatar_url = t.avatarUrl, e.globalData.userInfo.nick_name = t.nickName;
                }
            });
        } else wx.navigateBack();
    },
    backFn_livevideo: function() {
        this.setData({
            livevideo: !1
        }), wx.navigateBack();
    },
    backHandleFun: function() {
        var a = this, t = getCurrentPages(), n = t[t.length - 2];
        "pages/live-video/live-video/room" === n.route || "pages/live-video/live-video/index" === n.route ? wx.request({
            url: e.globalData.uchaozuBase + "/api/miniapps/login/userinfo",
            data: Object.assign({
                ids: e.globalData.userInfo.user_id + ""
            }, e.getSecret()),
            success: function(e) {
                var t = e.data;
                if (200 === t.code && t.data.length) {
                    var n = t.data[0];
                    "" !== n.nick_name && "" !== n.avatar_url ? wx.navigateBack() : a.setData({
                        livevideo: !0
                    });
                } else a.setData({
                    livevideo: !0
                });
            },
            fail: function() {
                wx.showToast({
                    title: "网络请求失败！"
                });
            }
        }) : wx.navigateBack();
    },
    userInfoHandler: function(a) {
        var t = this, n = e.getSecret();
        "getPhoneNumber:ok" == a.detail.errMsg && wx.getStorage({
            key: "code",
            success: function(o) {
                wx.showLoading({
                    mask: !0
                }), wx.request({
                    url: e.globalData.uchaozuBase + "/api/miniapps/login/wxlogin",
                    data: {
                        currtime: n.currtime,
                        sign: n.sign,
                        code: o.data,
                        iv: a.detail.iv,
                        data: a.detail.encryptedData
                    },
                    success: function(a) {
                        wx.hideLoading(), 200 == a.data.code ? (a.data.data.nickname && (a.data.data.nick_name = a.data.data.nickname), 
                        wx.setStorage({
                            key: "userInfo",
                            data: a.data.data
                        }), e.globalData.userInfo = a.data.data, wx.getStorage({
                            key: "browse",
                            success: function(a) {
                                wx.request({
                                    url: "https://uc.haozu.com/api/miniapps/view/add",
                                    data: {
                                        uid: e.globalData.userInfo.user_id,
                                        currtime: n.currtime,
                                        sign: n.sign,
                                        data: a.data
                                    },
                                    success: function(a) {
                                        wx.removeStorage({
                                            key: "browse",
                                            success: function(a) {}
                                        }), wx.removeStorage({
                                            key: "building",
                                            success: function(a) {}
                                        }), wx.removeStorage({
                                            key: "space",
                                            success: function(a) {}
                                        });
                                    }
                                });
                            },
                            fail: function(a) {}
                        }), new Promise(function(a, t) {
                            var n = wx.getStorageSync("dataInfo");
                            wx.request({
                                url: e.globalData.uchaozuBase + "/api/miniapps/collect/add/",
                                data: Object.assign(n, e.getSecret(), {
                                    uid: e.globalData.userInfo.user_id
                                }),
                                success: function(a) {
                                    a.data;
                                }
                            });
                            var o = wx.getStorageSync("HdataInfo");
                            wx.request({
                                url: e.globalData.uchaozuBase + "/api/miniapps/collect/add/",
                                data: Object.assign(o, e.getSecret(), {
                                    uid: e.globalData.userInfo.user_id
                                }),
                                success: function(a) {
                                    a.data;
                                }
                            });
                        }).then(function(a) {}, function(a) {}), e.globalData.needBack ? t.backHandleFun() : wx.reLaunch({
                            url: "/pages/my/index?phone=" + a.data.data.mobile
                        })) : 300 == a.data.code ? wx.showModal({
                            content: "您的微信尚未绑定手机号，是否前往绑定",
                            success: function(a) {
                                a.confirm ? wx.navigateTo({
                                    url: "/pages/bind/index"
                                }) : a.cancel;
                            }
                        }) : wx.showToast({
                            icon: "none",
                            title: a.data.msg,
                            mask: !0
                        }), wx.getStorageSync("userInfo").user_id && wx.login({
                            success: function(a) {
                                a.code && wx.setStorage({
                                    key: "code",
                                    data: a.code
                                });
                            }
                        });
                    },
                    fail: function(a) {}
                });
            }
        });
    },
    onLunch: function() {
        wx.getStorageSync("userInfo");
        wx.login({
            success: function(a) {
                a.code && wx.setStorage({
                    key: "code",
                    data: a.code
                });
            }
        });
    },
    refuse: function() {
        wx.navigateTo({
            url: "/pages/login/index"
        });
    },
    showFn: function() {
        this.setData({
            hidden_template: !0
        });
    },
    sureFn_template: function() {
        wx.redirectTo({
            url: "/pages/bind/index"
        });
    },
    backFn_template: function() {
        this.setData({
            hidden_template: !1
        });
    },
    phone_input_fn: function(a) {
        this.setData({
            username: a.detail.value
        });
    },
    pass_input_fn: function(a) {
        this.setData({
            password: a.detail.value
        });
    },
    onLoad: function(a) {
        var t = this;
        a.phone && t.setData({
            username: a.phone
        }), e.globalDataLoad(t, "tel-phone"), e.globalData.userInfo && this.setData({
            userInfo: e.globalData.userInfo || {},
            resPhone: e.globalData.userInfo && e.globalData.userInfo.mobile || "",
            hasUserInfo: !0
        });
    }
};

t.data.hidden_template = a.hidden_template, Page(t);